package gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;

import control.Generator;
import data.*;
import data.model.TaskGraph;
import data.mxgraph.mxTaskGraph;

public class GUIMenu extends JMenu implements ActionListener {
	
	private JMenuItem newMenuItem;
	
	private JMenuItem genMenuItem;
	
	private JMenuItem exitMenuItem;
	
	public GUIMenu(String name)
	{
		super(name);
		createComponents();
	}
	
	private void createComponents() 
	{
	 	
	newMenuItem = new JMenuItem("New");
	add(newMenuItem);
	newMenuItem.addActionListener(this);
	
	genMenuItem = new JMenuItem("Generate");
	add(genMenuItem);
	genMenuItem.addActionListener(this);
	
	exitMenuItem = new JMenuItem("Exit");
	add(exitMenuItem);
	exitMenuItem.addActionListener(this);
		
	}

	

	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource() == newMenuItem)
		{
			ActionList.clear();
			ProcList.clear();
			TaskGraph.clear();
			mxTaskGraph.clear();
			ActionPanel.updateActions();
			ProcessorPanel.updateProcs();
			Generator.addScheduleName();
			
			
			JOptionPane.showMessageDialog(null,"Data cleared.","Done",
					JOptionPane.INFORMATION_MESSAGE);
		}
		if(e.getSource() == genMenuItem)
		{
			Generator.runGenerator();
		}
		if(e.getSource() == exitMenuItem)
		{
			System.exit(0);
		}

	}

}
